<?php

use yii\db\Migration;

class m171122_020529_create_channel_distribution extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }

    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%channel_distribution}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'name' => $this->string(50)->defaultValue(null)->comment('名称'),
                'contacts' => $this->string(20)->defaultValue(null)->comment('联系人'),
                'mobile' => $this->string(11)->defaultValue(null)->comment('电话'),
                'admin' => $this->string(20)->defaultValue(null)->comment('负责人'),
                'admin_id' => $this->integer(11)->defaultValue(0)->comment('负责人id'),
                'created_at' => $this->integer(11)->defaultValue(0)->comment('创建时间')
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropTable('{{%channel_distribution}}');
        }
    }

    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m171031_014745_create_manage_time cannot be reverted.\n";

        return false;
    }
    */
}
